home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / cqa.zip / CLASSPTR.TCP < prev    next >
Text File  |  1991-04-01  |  717b  |  24 lines

  1. QUESTION:  I need to create a pointer to member function but have not
  2.            been successful. How is this done?
  3.  
  4. ANSWER:    The following is an example of how a pointer to a member
  5.            function may be created and used:
  6.  
  7. #include <stdio.h>
  8.  
  9. class testclass {
  10.   public:
  11.   void test(int x) { printf("-> %d <-", x); }
  12. };
  13.  
  14. void main(void)
  15. {
  16.   testclass xxx;
  17.   void (testclass::*p_func) (int);    // p_func is type pointer to member
  18.                                       // function accepting an int and
  19.                                       // returning void
  20.  
  21.   p_func = testclass::test;           // assign p_func the address of test
  22.   (xxx.*p_func) (3);                  // call test
  23. }
  24.